


void tempControl(){
  if(fridgeTemp1 > fridgeSetTemp1 + tempHysteresis){
    requestCompOn = true;
  }

  if(fridgeTemp1 <  fridgeSetTemp1 - tempHysteresis){
    requestCompOn = false;
  }
  
  controlCompressor();
}


void controlCompressor(){
  if(requestCompOn){
    if((!compressorSaftetyOverride && millis() < minCompressorOFFtime) || (millis()- millisCompressorOFF > minCompressorOFFtime) && !compressorON){
          compressorON = true;
          digitalWrite(TEMP_CONTROL_COOL,1);
          millisCompressorON = millis();
    }
  }
  else{
    if((millis() - millisCompressorON > minCompressorONtime) && compressorON){
      digitalWrite(TEMP_CONTROL_COOL,0);
      compressorON = false; 
      millisCompressorOFF = millis();
    }
  }

manageEE2(compressorON); 
}

void manageEE2(boolean currentState){
if(EEpromCompressorState == 1 && !currentState && (millis()- millisCompressorOFF > minCompressorOFFtime)){
  if(!DEBUG)
  EEPROM.write(0,0);  
  EEpromCompressorState = 0; 
   Serial.println("EEPROM Write: 0");
}
if(currentState && EEpromCompressorState == 0){
  if(!DEBUG)
  EEPROM.write(0,1);  
  EEpromCompressorState = 1; 
   Serial.println("EEPROM Write: 1");
}
return;
}


